﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;
using HZ.DrugTrade.Model;
using System.Data;
using HZ.DrugTrade.Model.Enum;

namespace HZ.DrugTrade.Web.Admin.RelationQuery
{
    public partial class RelationShipDelLog : BasePage
    {
        public RelationShipDelLog()
        {
            this.ModuleNo = Module.配送关系管理.ToString();
            this.PageOperateType = OperateType.企业不良记录.ToString();
        }

      
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        IBLL_AreaDistributionDelLog iselectRelation = Factory.BLL_AreaDistributionDelLog();

        string procureCatalogId = "";

        protected void Page_Load(object sender, EventArgs e)
        {

            /*
             Edited by sinodier 
             * 暂时未对企业开放
             */
            if (!CurrentAccount.GetUser().UserRole.RoleID.Equals("03"))
            {
                PageError("暂未开放，无权操作！", this.ReturnUrl);
            }
            if (!IsPostBack)
            {
               
                Banding();//绑定
            }
        }
        public HZ.DrugTrade.Model.Query.AreaDistributionDelLog GetWhere()
        {
            HZ.DrugTrade.Model.Query.AreaDistributionDelLog where = new HZ.DrugTrade.Model.Query.AreaDistributionDelLog();
            string strAreaID = GetAreaID();
            if (string.IsNullOrEmpty(strAreaID) == false && strAreaID.EndsWith("0000") == false)
            {
                where.AreaID = strAreaID;//地区ID
            }
            where.CompanyName_PS = txtCompany.Text.Trim();
            where.CompanyName_TB = txtCompanyID_TB.Text.Trim();//投标企业
            //if (CurrentAccount.GetUser().UserRole.RoleID == "02" || CurrentAccount.GetUser().UserRole.RoleID == "05")
            //{
            //    where.Append=string.Format(" CompanyID_TB='{0}' and CompanyID_PS='{}' ",CurrentAccount.GetUser().UserID);
            //}

            where.SortFields = " AreaID ";
            return where;
        }
        /// <summary>
        /// 绑定
        /// </summary>
        private void Banding()
        {
            int totalCount = 0;
            AspNetPager1.PageSize = Constants.GRIDVIEW_PAGE_SIZE;
            IList<HZ.DrugTrade.Model.View.AreaDistributionDelLog> dt = iselectRelation.GetAreaDistributionDelCompany(GetWhere(), AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
            gvwProduceCatalog.DataSource = dt;
            gvwProduceCatalog.DataBind();
            AspNetPager1.RecordCount = totalCount;
        }
       protected void AspNetPager1_OnPageChanged(object sender, EventArgs e)
        {
            Banding();
        }

        protected void btnSelect_Click(object sender, EventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = 1;
            Banding();
        }
        /// <summary>
        /// 获取默认选中的地区编号串
        /// </summary>
        /// <returns></returns>
        protected string GetDefaultAreaString()
        {
            //默认城市 江苏省 320000
            string defaultCity = "";
            string defaultProvince = "";

            Model.Area aArea = CurrentAccount.GetCurrentDeployArea();  //获取当前实施地区的地区

            defaultProvince = aArea.AreaID;

            string strArea = "";
            //显示默认地区
            strArea += "," + "\"" + defaultProvince + "\"";
            this.ddlProvice.Enabled = false;
            if (!string.IsNullOrEmpty(defaultCity))
            {
                strArea += "," + "\"" + defaultCity + "\"";
                this.ddlCity.Enabled = false;
            }
            else if (!string.IsNullOrEmpty(Request.Form["ctl00$ContentPlaceHolder1$ddlCity"]))
            {
                strArea += "," + "\"" + Request.Form["ctl00$ContentPlaceHolder1$ddlCity"] + "\"";
            }

            if (!string.IsNullOrEmpty(Request.Form["ctl00$ContentPlaceHolder1$ddlCountry"]))
            {
                strArea += "," + "\"" + Request.Form["ctl00$ContentPlaceHolder1$ddlCountry"] + "\"";
            }

            return strArea;
        }
        /// <summary>
        /// 获取地区ID
        /// </summary>
        /// <returns></returns>
        private string GetAreaID()
        {
            string areaId = "";

            //首次进入使用系统部署所在区域ID
            Model.Area aArea = CurrentAccount.GetCurrentDeployArea();  //获取当前实施地区的地区
            areaId = aArea.AreaID;

            //优先获取城市，再次省份
            if (new Common.ConvertHelper(Request.Form["ctl00$ContentPlaceHolder1$ddlCity"]).String != Constants.ALL_ITEM_VALUE)
            {
                areaId = Request.Form["ctl00$ContentPlaceHolder1$ddlCity"];
            }
            else if (new Common.ConvertHelper(Request.Form["ctl00$ContentPlaceHolder1$ddlProvice"]).String != Constants.ALL_ITEM_VALUE)
            {
                areaId = Request.Form["ctl00$ContentPlaceHolder1$ddlProvice"];
            }

            return areaId;
        }

        protected void btnExport_Click(object sender, EventArgs e)
        {
            int totalCount = 0;
            IList<Model.View.AreaDistributionDelLog> purchaseOrderDetailList = iselectRelation.GetAreaDistributionDelCompany(GetWhere(), 1, 0, out totalCount);
            System.Data.DataTable tb = HZ.Data.ModelConvert.GetDataTableFromModel(purchaseOrderDetailList);
            HZ.Excel.ExcelHelper.ExportDataForWeb(tb, gvwProduceCatalog);
        }

    }
}
